package com.yenchingcheng;

import com.yenchingcheng.cache.ShapeCache;
import com.yenchingcheng.entity.Circle;
import com.yenchingcheng.entity.Rectangle;
import com.yenchingcheng.entity.Square;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author Yenchingcheng
 * @Date 2023/7/31 15:05
 * @Description 测试类
 **/
public class Test {

    /**测试结果--三个类利用已经获取到的一个对象各自clone了属性值相同的三个对象：
     *
     * circle:Circle{id='1', type='Circle'},hashcode:1956725890
     * circle:Circle{id='1', type='Circle'},hashcode:356573597
     * circle:Circle{id='1', type='Circle'},hashcode:1735600054
     * +++++++++++++++++++++++++++++++++++++++
     * rectangle:Rectangle{id='2', type='Rectangle'}, hashcode:21685669
     * rectangle:Rectangle{id='2', type='Rectangle'}, hashcode:2133927002
     * rectangle:Rectangle{id='2', type='Rectangle'}, hashcode:1836019240
     * +++++++++++++++++++++++++++++++++++++++
     * square:Square{id='3', type='Square'}, hashcode:325040804
     * square:Square{id='3', type='Square'}, hashcode:1173230247
     * square:Square{id='3', type='Square'}, hashcode:856419764
     */
    public static void main(String[] args) {
        ShapeCache.init();

        List<Circle> circles = new ArrayList<>();
        for (int i = 0; i < 3; i++) {
            Circle circle = (Circle) ShapeCache.getShape("1");
            circles.add(circle);
        }
        for (Circle circle : circles) {
            System.out.println("circle:" + circle + ",hashcode:" + circle.hashCode());
        }

        System.out.println("+++++++++++++++++++++++++++++++++++++++");

        List<Rectangle> rectangles = new ArrayList<>();
        for (int i = 0; i < 3; i++) {
            Rectangle rectangle = (Rectangle) ShapeCache.getShape("2");
            rectangles.add(rectangle);
        }
        for (Rectangle rectangle : rectangles) {
            System.out.println("rectangle:" + rectangle + ", hashcode:" + rectangle.hashCode());
        }

        System.out.println("+++++++++++++++++++++++++++++++++++++++");

        List<Square> squares = new ArrayList<>();
        for (int i = 0; i < 3; i++) {
            Square square = (Square) ShapeCache.getShape("3");
            squares.add(square);
        }
        for (Square square : squares) {
            System.out.println("square:" + square + ", hashcode:" + square.hashCode());
        }

    }
}
